<template>
  <div>
    <el-card header="请先登录" class="login-card">
      <el-form @submit.native.prevent="login">
        <el-form-item label="用户名">
          <el-input v-model="model.username"></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input v-model="model.password" type="password"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="parimary" native-type="sublimt">登录</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      model: {}
    };
  },
  mounted() {},
  methods: {
    async login() {
      const res = await this.$http.post("/login",this.model);
      // console.log(res)
      localStorage.token = res.data
      // console.log(res);
      this.$router.push("/")
      this.$message({
        type: "success",
        message: "登录成功"
      })
    }
  }
};
</script>

<style lang='css' scoped>
* {
  padding: 0;
  margin: 0;
}
.login-card {
  margin: 0 auto;
  width: 40rem;
  text-align: center;
}
</style>